import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description
 * User: cjc
 * Date: 2025-03-07
 * Time: 16:14
 */
public class Test {
    public static void main(String[] args) {
        //test1();
        //test2();
        //test3();
        //Sort();
        BubbleSort();
    }
    public static void BubbleSort() {
        int[] array = {2,5,3,6,34,23};
        for (int i = 0; i < array.length; i++) {
            for (int j = i; j < array.length-1; j++) {
                if(array[j]>array[j+1]) {
                    int temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                }
            }
        }
            System.out.println(Arrays.toString(array));
    }
    public static void Sort() {
        int[] arr = {9, 5, 2, 7};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static int finderfen(int[] array,int num) {
        int i = 0;
        int j = array.length - 1;
        while(i <= j) {
            int m = (i + j) / 2;
            if(array[m] == num) {
                return m;
            } else {
                if(array[m] > num) {
                    j = m - 1;
                } else {
                    i = m +1;
                }
            }
        }
        return -1;
    }
    public static void test3() {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        int ret = finderfen(array,10);
        if(ret == -1) {
            System.out.println("没有找到");
        } else {
            System.out.println("找到了下标为："+ret);
        }
    }
    public static int find(int[] array,int k) {
        for (int i = 0; i < array.length; i++) {
            if(array[i] == k) {
                return i;
            }
        }
        return -1;
    }
    public static void test2() {
        int[] array = {3,5,2,9,56,34};
        int ret = find(array,56);
        if(ret == -1) {
            System.out.println("没有找到");
        } else {
            System.out.println("找到了下标为："+ret);
        }
    }
    public static int[] CopyArray(int[] array) {
        int[] copyarray = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copyarray[i] = array[i];
        }
        return copyarray;
    }
    public static void test1() {
        int[] array = {1,2,3,4,5};
        int[] newarray = CopyArray(array);
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(newarray));
        int[] array3 = {1,2,3,4,5};
        int[] newarray2 = Arrays.copyOf(array,array.length);
        System.out.println(Arrays.toString(newarray2));
        int[] newarray3 = new int[array.length];
        System.arraycopy(array,2,newarray3,1,3);
        System.out.println(Arrays.toString(newarray3));
        int[] newarray4 = Arrays.copyOfRange(array,2,4);
        System.out.println(Arrays.toString(newarray4));
        int[] newarray5 = Arrays.copyOfRange(array,2,14);
        System.out.println(Arrays.toString(newarray5));
        int[] newarray6 = Arrays.copyOf(array,array.length*2);
        System.out.println(Arrays.toString(newarray6));
    }
}
